/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs.tools;

import com.jfinal.render.Render;
import java.io.File;

/**
 *
 * @author Administrator
 */
public class VideoRender extends Render {

    private File file;
    private String type;

    public VideoRender(File file, String type) {
        this.file = file;
        this.type = type;
    }

    @Override
    public void render() {
        try {
            response.reset();

            response.setContentType("video/mpeg4");

//    response.setHeader("Cache-Control", "no-cache");
//    response.setDateHeader("Expires", 0);
            java.io.FileInputStream fis = new java.io.FileInputStream(new File(file.getAbsolutePath()));
            java.io.OutputStream os = response.getOutputStream();
            byte[] buf = new byte[4096];
            int bytes = 0;
            while ((bytes = fis.read(buf)) != -1) {
                os.write(buf, 0, bytes);
            }

//     out.clear();
//    out = pageContext.pushBody();
            fis.close();
            os.close();
        } catch (Exception e) {
        }
    }

}
